home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3405 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  50 lines

  1. Path: news.clark.net!not-for-mail
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: overiding c++ stream classes anyone?
  5. Date: 23 Jan 1996 17:29:02 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Message-ID: <4e35su$sq4@clarknet.clark.net>
  8. References: <4cqbja$62n@earth.njcc.com> <4e1d5f$5en@news02.comp.pge.com>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  14.  
  15. Phillip Knight (psk3@pge.com) wrote:
  16. : I have pulled the last hair out of my head and still have not solved this 
  17. : problem:
  18. :     class X : public ostream {
  19. :     public:
  20. :     ...
  21. :     X& operator<<(X& (*f)(X&)) { return (*f)(*this); }
  22. :     };
  23. :     X& newl(X& os) {
  24. :         cerr << "this never gets printed" << endl;
  25. :     }
  26.  
  27. This function needs to return something (presumably foo).
  28.  
  29. :     main() {
  30. :        X foo;
  31. :        foo << "test one";
  32. :        foo << endl;
  33. :        foo << "test two" << endl;
  34. :     }
  35. : so the problem is simple: how do i get my manipulator newl to be called?
  36.  
  37. By calling it, no? You're calling endl in main(). Don't you mean to use
  38. newl instead? 
  39.  
  40.     foo << newl;
  41.     foo << "test two" << newl;
  42.  
  43.  
  44.